Empty repr(Rust) enums are ZSTs - #2293
Conversation
This comment has been minimized.
This comment has been minimized.
|
Error: Label T-lang can only be set by Rust team members Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
|
cc @traviscross As per #2262 (comment) , here's a followup PR to extend the ZST guarantee to zero-variant |
|
This seems obvious to me: of course an uninhabitable type with no variants and no fields needn't take up any space, so might as well be guaranteed a ZST. Especially since this doesn't say anything about alignment it seems fine. @rfcbot merge lang (Since 1-ZSTs are extra meaningful in various ways it'd probably also be fine to make these 1-ZSTs specifically, not just ZSTs, but let's accept the proposal here for just "size ≡ 0" for now since we have it in front of us.) |
|
@scottmcm has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot reviewed |
|
These types are uninhabited, but for the purposes of layout, yes, they should not affect the size (or alignment) of whatever they're put inside. @rfcbot reviewed |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
@rfcbot reviewed |
|
I would appreciate if there’s some (at least minor) indication about this case being an uninhabited type, too; because those feel different from the more typical case of a “ZST”. Also, looking up at the previous section about uninhabited types, which lists Maybe the (or part of the) callout needed would just be in that previous section about uninhabited types, noting the fact that types can be uninhabited and zero-sized at the same time. (And that uninhabited types often - but not always - are zero-sized.) |
I added a note to
I think
|
|
Hmm, maybe the I'll put the note that that types can be uninhabited and zero-sized at the same time in this PR then. |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
… r=davidtwco Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees. First commit is the guarantees that T-lang already FCP'd in rust-lang/reference#2262 . Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293 (FCP now completed)
… r=davidtwco Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees. First commit is the guarantees that T-lang already FCP'd in rust-lang/reference#2262 . Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293 (FCP now completed)
… r=davidtwco Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees. First commit is the guarantees that T-lang already FCP'd in rust-lang/reference#2262 . Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293 (FCP now completed)
… r=davidtwco Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees. First commit is the guarantees that T-lang already FCP'd in rust-lang/reference#2262 . Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293 (FCP now completed)
… r=davidtwco Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees. First commit is the guarantees that T-lang already FCP'd in rust-lang/reference#2262 . Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293 (FCP now completed)
… r=davidtwco Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees. First commit is the guarantees that T-lang already FCP'd in rust-lang/reference#2262 . Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293 (FCP now completed)
Rollup merge of #157905 - zachs18:randomize-layout-zst-note, r=davidtwco Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees. First commit is the guarantees that T-lang already FCP'd in rust-lang/reference#2262 . Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293 (FCP now completed)
Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs See rust-lang/reference#2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees. First commit is the guarantees that T-lang already FCP'd in rust-lang/reference#2262 . Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at rust-lang/reference#2293 (FCP now completed)
|
@rustbot label -S-waiting-on-author |
When "zero sized" is used in predicate position, we don't hyphenate it. Let's also move the link definition to the bottom.
The phrasing of this rule was a bit indirect due to language being carried over from other rules that's less applicable here. Let's make this clearer.
310fcc5 to
cd7c8a8
Compare
|
Thanks @zachs18. |
Guarantee that enums with Rust representation with no variants are ZSTs.
Followup to #2262 , (which guaranteed the same for enums with Rust representation with a single variant whose fields are all ZSTs).